package paskal.audio.player;

import java.io.PrintStream;
import java.io.PrintWriter;

/**
 * This class implements custom exception for player.
 */
public class PlayerException extends Exception {
	private static final long serialVersionUID = 4201195946883414503L;
	public static final String GAIN_CONTROL_NOT_SUPPORTED = "Gain control not supported";
	public static final String VOLUME_CONTROL_NOT_SUPPORTED = "Volume control not supported";
	public static final String PAN_CONTROL_NOT_SUPPORTED = "Pan control not supported";
	public static final String WAIT_ERROR = "Wait error";
	public static final String CANNOT_INIT_LINE = "Cannot init line";
	public static final String SKIP_NOT_SUPPORTED = "Skip not supported";
	private Throwable cause = null;

	public PlayerException() {
		super();
	}

	public PlayerException(String msg) {
		super(msg);
	}

	public PlayerException(Throwable cause) {
		super();
		this.cause = cause;
	}

	public PlayerException(String msg, Throwable cause) {
		super(msg);
		this.cause = cause;
	}

	public Throwable getCause() {
		return cause;
	}

	/**
	 * Returns the detail message string of this throwable. If it was created
	 * with a null message, returns the following: (cause==null ? null :
	 * cause.toString()).
	 */
	public String getMessage() {
		if (super.getMessage() != null) {
			return super.getMessage();
		} else if (cause != null) {
			return cause.toString();
		} else {
			return null;
		}
	}

	public void printStackTrace() {
		printStackTrace(System.err);
	}

	public void printStackTrace(PrintStream out) {
		synchronized (out) {
			PrintWriter pw = new PrintWriter(out, false);
			printStackTrace(pw);
			pw.flush();
		}
	}

	public void printStackTrace(PrintWriter out) {
		if (cause != null)
			cause.printStackTrace(out);
	}
}